// pages/dzxq/dzxq.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    roomId: "",
    roomDetail: {}
  },

  toxgfy: function () {
    wx.navigateTo({
      url: '../xgfy/xgfy'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      roomId: options.room_id
    })
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.url + '/wx/house/room/detail',
      data: {
        token: wx.getStorageSync('token'),
        roomId: this.data.roomId
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: res => {
        res.data.roomDetail = { "houseName": "五象大道", "roomcode": "101", "floorName": "1", "houseTypeName": "两房一厅", "roomArea": "52m^2", "price": "1000/月", "chargemode": "现金支付", "address": "北京天安门广场", "furniture": "双人床，冰箱，电风扇，空调，洗衣机，电视机，电脑，电磁炉" }

        var temp = res.data.roomDetail.furniture.split("，");
        var furnitureList = [];
        if (temp.length == 1 && temp[0] == "") {
          furnitureList = []
        } else {
          for (var i = 0; i < temp.length; i++) {
            furnitureList.push(temp[i]);
          }
        }
        res.data.roomDetail["furniture"] = furnitureList;
        console.log(res);
        that.setData({
          roomDetail: res.data.roomDetail
        })
      },
      fali: res => {
        wx.showToast({
          title: '房源详情获取失败',
          image: '../../image/shibai.png',
          duration: 2000
        })
      },
      complete: res =>
        wx.hideLoading()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})